<?php
/**
 * 楼盘视频信息上传
 */
namespace app\manage\controller;
use \think\Validate;
class BuildingList extends \app\common\controller\Manage
{
    //上移或下移
    public function upload(){
        $data = input('param.');
        $order = $data['order'];
        $map['id'] = array('eq',$data['id']);
        $result =  \app\common\model\Building::where($map) -> find();
        if($data['sign']){
            $list = $result['list_enterlo'];
            $mapw[] = array('list','eq',$list);
            $result1 = \app\common\model\BuildingListEnterlo::where($mapw) -> find();
        }else{
            $list = $result['list'];
            $mapw[] = array('list','eq',$list);
            $result1 = \app\common\model\BuildingList::where($mapw) -> find();
        }
        $building_id = $result1['building_id'];
        $num = explode(',',$building_id);
        switch ($order){
            case 'up':for($i=0;$i<count($num);$i++){
                        $num1 = $num[$i];
                        if($num1 == $data['id']){
                            $num[$i] = $num[$i-1];
                            $num[$i-1] = $data['id'];
                        }
                        }; $tmp = $num;break;
            case 'down':for($i=0;$i<count($num);$i++){
                            $num1 = $num[$i];
                        if($num1 == $data['id']){
                            $num[$i] = $num[$i+1];
                            $num[$i+1] = $data['id'];
                            $tmp = $num;break;
                        }
                    };break;
            case 'top': $tmp = array($data['id']);
                        for($i=0;$i<count($num);$i++){
                            $num1 = $num[$i];
                            if($num1 !== $data['id']){
                            $tmp[] = $num1;
                            }
                        };break;default;
        }
        $map1['list'] = array('eq',$list);
        foreach ($tmp as $value){
            $val  = $val.','.$value;
        }
        $val = ltrim($val,',');
        if($data['sign']){
            \app\common\model\BuildingListEnterlo::where($map1) -> setField('building_id',$val);
        }else{
            \app\common\model\BuildingList::where($map1) -> setField('building_id',$val);
        }
        return [
            'code' => '1',
            'message' => '移动成功',
        ];
    }
}